home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 90 / CD Actual 90.iso / Software3D / K-3D / k3d-0.4.2.1 / shaders / k3d_spacecloud.sl < prev    next >
Encoding:
Text File  |  2004-07-23  |  2.5 KB  |  98 lines

  1. /*
  2.  * TLSpaceCloud.sl - perform turbulence function to add more dimension to
  3.  *    texture-map and try to make it not so obvious that it is a texture-map.
  4.  *
  5.  *
  6.  * DESCRIPTION:
  7.  *   Uses a pulse function to tapper off the edges of the texture
  8.  *
  9.  * PARAMETERS:
  10.  *   txtFile -- texture map
  11.  *   startPulse -- start of pulse function.
  12.  *   endPulse -- end of pulse function
  13.  *   fuzz -- amount to blur the edges of the pulse
  14.  *   minAdjust -- amount that can be subtracted from value
  15.  *   maxAdjust -- amount that can be added to the value
  16.  *   maxOpacity -- maximin opacity for the surface
  17.  *
  18.  * HINTS:
  19.  *  Only tested on rectanglar patch.
  20.  *
  21.  * AUTHOR: Tal Lancaster
  22.  *
  23.  *
  24.  * HISTORY:
  25.  *  Created: 6/1/95
  26.  *  
  27.  *  tal 3/2/97  -- Cleaned up code, removed many constants, added comments
  28.  *  tal 2/23/97 -- Originally tried using fBm to create turbulence.  But
  29.  *      I was never happy with the results.  So now am just using noise over
  30.  *      u,v. 
  31.  */
  32.  
  33. #define  MINFREQ 1.1
  34. #define MAXFREQ 6
  35.  
  36. #define snoise(x) (2 * noise(x) - 1)
  37. #define snoise2(x, y) (2 * noise(x, y) - 1)
  38.  
  39. #define adjustNoise2(x, y, minVal, maxVal) \
  40.     snoise2 (x,y) * ((maxVal)-(minVal)+(minVal))
  41.  
  42. /* separate fuzzes */
  43. #define smoothPulse2Fuzz(a, b, afuzz, bfuzz, loc) \
  44.   (smoothstep (a-afuzz, a, loc) - \
  45.    smoothstep (b, b+bfuzz, loc) )
  46.  
  47. surface k3d_spacecloud(
  48.   string txtFile = "";
  49.   float startPulse = .2; /* .1 .2 .3 .01 */
  50.   float endPulse = .9; /* .9 .8 .7 .8 */
  51.   float afuzz = .1;
  52.   float bfuzz = .2;
  53.   float minAdjust = -.4;
  54.   float maxAdjust = .4;
  55.   float maxOpacity = .4;
  56. )
  57. {
  58.   float value = 0;
  59.   float f;
  60.   color Ct;
  61.   point PP;
  62.   float freq, i, size;
  63.   float adjust;
  64.   float ss, tt;
  65.   
  66.  
  67.   if (txtFile != "")
  68.     Ct = color texture (txtFile, s, 1-t);
  69.   else
  70.     Ct = color (.3, .3, .3);
  71.  
  72.     PP = transform ("object", P);
  73.   /* fractalsum */
  74.   for (f = MINFREQ; f < MAXFREQ; f += 1)
  75.     value += abs(snoise (PP * f))/f;
  76.  
  77. #if 0
  78. #define  MINFREQ 1.1
  79. #define MAXFREQ 6
  80.     /* Old way */
  81.  
  82.     fBm (P, noiseScale, octaves, PP, freq, i, size, adjust);
  83.     /*printf ("%.3f %.3f: adjust %.3f\n", s, t, adjust);*/
  84.     
  85. #else
  86.     adjust = adjustNoise2 (u, v, minAdjust, maxAdjust);
  87.     ss = s + adjust;
  88.     tt = t + adjust;
  89.     /* printf ("%.3f %.3f: %.3f %.3f\n", s, t, ss-s, tt-t); */
  90.     
  91. #endif
  92.     Oi = value * smoothPulse2Fuzz (startPulse, endPulse, afuzz, afuzz, ss) * 
  93.         smoothPulse2Fuzz (startPulse, endPulse, bfuzz, afuzz, tt);
  94.  
  95.     Oi *= maxOpacity;
  96.     Ci = Ct * Oi * 1.75  /* saturate colors */;
  97. }
  98.